package com.yuanxin.contacts;

import java.util.HashMap;
import java.util.Map;

/**
 * 姓氏多音字调整
 * 后期如果发现更多，在pinyins里添加即可
 */
public class FirstNamePinYinUitls {

    //姓氏多音字
    private static Map<String, String> pinyins = new HashMap<String, String>() {{
        put("仇", "QIU");//"仇"
        put("朴", "PIAO");//"朴"
        put("单", "SHAN");//"单"
        put("解", "XIE");//"解"
        put("区", "OU");//"区"
        put("查", "ZHA");//"查"
        put("繁", "PO");//"繁"
        put("瞿", "QU");//"瞿"
        put("员", "YUN");//"员"
        put("能", "NAI");//"能"
        put("阚", "KAN");//"阚"
        put("都", "DU");//"都"
        put("乜", "NIE");//"乜"
        put("缪", "MIAO");//"缪"
        put("句", "GOU");//"句"
        put("阿", "E");//"阿"
        put("沈", "SHEN");//"沈"
        put("谌", "CHEN");//"谌"
        put("盖", "GE");//"盖"
        put("乐", "YUE");//"乐"
        put("种", "CHONG");//"种"
        put("覃", "QIN");//"覃"
        put("折", "SHE");//"折"
        put("曾", "ZENG");//"曾"
        put("秘", "BI");//"秘"
        put("重", "CHONG");//"重"
        put("冼", "XIAN");//"冼"
        put("翟", "ZHAI");//"翟"
        put("黑", "HE");//"黑"
        put("吞", "TIAN");//"吞"
        put("不", "FOU");//"不"
        put("啜", "CHUAI");//"啜"
        put("术", "ZHU");//"术"
        put("传", "CHUAN");//"传"
        put("祭", "ZHAI");//"祭"
        put("尉迟", "YUCHI");//"尉迟"
        put("万俟", "MOQI");//"万俟"
        put("澹台", "TANTAI");//"澹台"
    }};

    /**
     * 替换姓名多音字拼音
     *
     * @param map 联系人
     */
    public static void replaceFirstNamePinYin(Map<String, Contact> map) {
        for (String contactKey : map.keySet()) {
            Contact contact = map.get(contactKey);
            if (contact.getFullName() != null && !"".equals(contact.getFullName()) && contact.getFullName().length() > 0)
               //contact.setFirstNamePinYin(Pinyin.toPinyin(contact.getFullName(), ""));
                //TODO
                contact.setFirstNamePinYin("");
            else{
                //没有名字的首字母拼音给一个~ ,因为~的值在ASCII码中最大，等于126，会排在最后
                contact.setFirstNamePinYin("~");
                continue;
            }
            for (String xing : pinyins.keySet()) {
                if (contact.getFullName().startsWith(xing)) {//这里判断名称的姓氏是否在多音字map中
                    contact.setFirstNamePinYin(pinyins.get(xing));//设置姓氏拼音
                }
            }
        }
    }
}
